package com.example.demo.mapper;

import com.example.demo.pojo.entity.Forum;
import com.example.demo.pojo.vo.UserCommentVO;
import com.example.demo.pojo.vo.UserForumVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface ForumMapper {

    @Select("select * from forum")
    List<Forum> list();

    @Insert("insert into forum(user_id, name, image, title, content, support, create_time) VALUES " +
            "(#{userId},#{name},#{image},#{title},#{content},#{support},#{createTime})")
    void insert(Forum forum);

    @Update("update forum set support=#{support} where id=#{id}")
    void updateSupport(Long id, Integer support);

    @Select("select count(id) from forum where user_id=#{userId}")
    Long getNumberById(Long userId);

    @Select("select u.id,u.name,fc.comment,fc.create_time from user u left join forum_comment fc on u.id=fc.user_id where fc.forum_id=#{forumId}")
    List<UserCommentVO> getUserCommentDetail(Long forumId);

    @Select("select u.id,u.name,f.image,f.title,f.content,f.create_time from user u left join forum f on u.id=f.id where f.id=#{forumId}")
    UserForumVO getUserForumDetail(Long forumId);
}
